<?php
class remove
{
	function paging($totalPage, $currentPage, $minPage, $previousPage, $nextPage, $maxPage)
	{
	    $minPage = ($currentPage - 1 > 1 ? ($currentPage - 1) : 1);
	    $maxPage = ($currentPage + 1 < $totalPage ? ($currentPage + 1) : $totalPage);
	    $previousPage = $currentPage - 1;
	    $nextPage = $currentPage + 1;
	}
	
	public static function showPage($totalPage, $page, $url)
	{
	    if ($totalPage > 1)
	    {
	        $minPage = 0;
	        $maxPage = 0;
	        $previousPage = 0;
	        $nextPage = 0;
	        #remove::paging($totalPage, $page, &$minPage, &$previousPage, &$nextPage, &$maxPage);
	        $currentPage = $page;
	        $minPage = ($currentPage - 1 > 1 ? ($currentPage - 1) : 1);
		    $maxPage = ($currentPage + 1 < $totalPage ? ($currentPage + 1) : $totalPage);
		    $previousPage = $currentPage - 1;
		    $nextPage = $currentPage + 1;
	    
	    
	    
	
	        $urlToFirst = sprintf($url, 1);
	        $urlToPrevious = sprintf($url, $previousPage);
	        $urlToNext = sprintf($url, $nextPage);
	        $urlToLast = sprintf($url, $totalPage);
	
	        if ($minPage == 1)
	        {
	            $linkToFirst = '';
	        }
	        else
	        if ($minPage == 2)
	        {
	            $linkToFirst = '<a href="'.$urlToFirst.'">1</a>';//link_to(1, $urlToFirst);
	        }
	        else
	        {
	            $linkToFirst = '<a href="'.$urlToFirst.'">1</a>...';//link_to(1, $urlToFirst).'...';
	        }
	
	        //$linkToPrevious = ($previousPage < 1 ? '' : link_to(PAGE_PREVIOUS, $urlToPrevious));
	
	        if ($maxPage == $totalPage)
	        {
	            $linkToLast = '';
	        }
	        else
	        if ($maxPage == $totalPage - 1)
	        {
	            $linkToLast = '<a href="'.$urlToLast.'">'.$totalPage.'</a>';//link_to($totalPage, $urlToLast);
	        }
	        else
	        {
	            $linkToLast = '<li>...</li><li><a href="'.$urlToLast.'">'.$totalPage.'</a>';//link_to($totalPage, $urlToLast).'</li>';
	        }
	
	        //$linkToNext = ($nextPage > $totalPage ? '' : link_to(PAGE_NEXT, $urlToNext));
	        $linkToPage = '';
	        for ($i = $minPage; $i <= $maxPage; $i++)
	        {
	            $urlToPage = sprintf($url, $i);
	            $linkToPage.=($i == $page ?'<li><a class="page_current">'.$i.'</a></li>' :'<li><a href="'.$urlToPage.'">'.$i.'</a></li>'.'');
	        }
	        echo  '<div>Trang: '.
	        '
	                     <ul>   
	                         <li>'.$linkToFirst.'</li>'.                         
	        $linkToPage.
	        '<li>'.$linkToLast.'</li>
	                     </ul>
	                   </div>
	               ';        
	    }
	}
}